home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Multimedia / Movie3.0 / Source / xanim / xsim.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-01  |  4.6 KB  |  173 lines

  1.  
  2. /*
  3.  * xanim_x11.c
  4.  *
  5.  * Copyright (C) 1990,1991,1992,1993,1994 by Mark Podlipec. 
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified and redistributed without
  9.  * fee for non-commerical purposes provided that this copyright notice is
  10.  * preserved intact on all copies and modified copies.
  11.  * 
  12.  * There is no warranty or other guarantee of fitness of this software.
  13.  * It is provided solely "as is". The author(s) disclaim(s) all
  14.  * responsibility and liability with respect to this software's usage
  15.  * or its effect upon hardware or computer systems.
  16.  *
  17.  */
  18.  
  19. #include "xanim.h"
  20.  
  21. ULONG X11_Get_True_Color(r,g,b,bits)
  22. register ULONG r,g,b,bits;
  23. {
  24.   register ULONG temp,temp_color;
  25.  
  26.   temp = (x11_red_bits >= bits)?(r << (x11_red_bits - bits))
  27.                                :(r >> (bits - x11_red_bits));
  28.   temp_color  = (temp << x11_red_shift) & x11_red_mask;
  29.  
  30.   temp = (x11_green_bits >= bits)?(g << (x11_green_bits - bits))
  31.                                  :(g >> (bits - x11_green_bits));
  32.   temp_color |= (temp << x11_green_shift) & x11_green_mask;
  33.  
  34.   temp = (x11_blue_bits >= bits)?(b << (x11_blue_bits - bits))
  35.                                 :(b >> (bits - x11_blue_bits));
  36.   temp_color |= (temp << x11_blue_shift) & x11_blue_mask;
  37.  
  38.   return(temp_color);
  39. }
  40.  
  41. ULONG X11_Get_Line_Size(xsize)
  42. ULONG xsize;
  43. {
  44.   ULONG line_size;
  45.  
  46.   if (x11_display_type == XA_MONOCHROME)
  47.        line_size = X11_Get_Bitmap_Width(xsize) / 8;
  48.   else line_size = xsize * x11_bytes_pixel;
  49.   return(line_size);
  50. }
  51.  
  52. void X11_Pre_Setup(argcp, argv,xa_user_visual,xa_user_class)
  53. int *argcp;
  54. char *argv[];
  55. LONG xa_user_visual;
  56. LONG xa_user_class;
  57. {
  58.   LONG i,vis_num,vis_i;
  59.  
  60.   /* setup up X11 variables */
  61.  
  62.   x11_depth = 24;
  63.   x11_class = TrueColor;
  64.   x11_cmap_size   = 256;
  65.  
  66.   /* Make sure x11_cmap_size is power of two */
  67.   { 
  68.     ULONG size;
  69.     size = 0x01; x11_disp_bits = 0;
  70.     while(size <= x11_cmap_size) { size <<= 1; x11_disp_bits++; }
  71.     size >>=1; x11_disp_bits--;
  72.     x11_cmap_size = 0x01 << x11_disp_bits;
  73.   }
  74.   x11_bit_order   = X11_LSB;
  75.   x11_bitmap_unit = 3;
  76.   x11_depth_mask = (0x01 << x11_depth) - 1;
  77.   x11_cmap_type = 0;
  78.  
  79.   if (x11_depth == 1)
  80.   {
  81.     x11_display_type = XA_MONOCHROME;
  82.     x11_bytes_pixel = 1; x11_bitmap_pad = x11_bitmap_unit; 
  83.     x11_cmap_flag = FALSE;
  84.     x11_black = 0;
  85.     x11_white = 1;
  86.     x11_bits_per_pixel = 1;
  87.     x11_byte_order = x11_bit_order;
  88.   }
  89.   else 
  90.   {
  91.     if (x11_depth > 16)
  92.         { x11_bytes_pixel = 4; x11_bitmap_pad = 32; }
  93.     else if (x11_depth > 8)
  94.         { x11_bytes_pixel = 2; x11_bitmap_pad = 16; }
  95.     else { x11_bytes_pixel = 1; x11_bitmap_pad = 8; }
  96.  
  97.     x11_bits_per_pixel = x11_depth;
  98.  
  99.     switch(x11_class)
  100.     {
  101.  
  102.       case StaticGray:
  103.     x11_display_type = XA_STATICGRAY;
  104.     x11_cmap_flag = FALSE;
  105.     break;
  106.       case GrayScale:
  107.     x11_display_type = XA_GRAYSCALE;
  108.     x11_cmap_flag = TRUE;
  109.     break;
  110.       case StaticColor:
  111.     x11_display_type = XA_STATICCOLOR;
  112.     x11_cmap_flag = FALSE;
  113.     break;
  114.       case PseudoColor:
  115.     x11_display_type = XA_PSEUDOCOLOR;
  116.     x11_cmap_flag = TRUE;
  117.     break;
  118.       case TrueColor:
  119.     x11_display_type = XA_TRUECOLOR;
  120.     x11_cmap_flag = FALSE;
  121.     break;
  122.       case DirectColor:
  123.     x11_display_type = XA_DIRECTCOLOR;
  124.     x11_cmap_flag = FALSE;
  125.     break;
  126.       default:
  127.     fprintf(stderr,"Unkown x11_class %lx\n",x11_class);
  128.     TheEnd();
  129.     }
  130.   }
  131.  
  132.     x11_red_mask = 255;
  133.     x11_green_mask = 255<<8;
  134.     x11_blue_mask = 255<<16;
  135.     x11_red_shift = 0;
  136.     x11_green_shift = 8;
  137.     x11_blue_shift = 16;
  138.     x11_red_bits = 8;
  139.     x11_green_bits = 8;
  140.     x11_blue_bits = 8;
  141.  
  142.   xa_cmap = (ColorReg *) malloc( x11_cmap_size * sizeof(ColorReg) );
  143.   if (xa_cmap==0) fprintf(stderr,"X11 CMAP: couldn't malloc\n");
  144.  
  145.   if (x11_verbose_flag == TRUE)
  146.   {
  147.     fprintf(stderr,"Selected Visual:  ");
  148.     fprintf(stderr,"NEXTSTEP");
  149.     fprintf(stderr," (%lx) \n",x11_display_type);
  150.     fprintf(stderr,"  depth= %ld  class= %ld  cmap size=%ld(%ld) bytes_pixel=%ld\n",
  151.         x11_depth, x11_class, x11_cmap_size, x11_disp_bits, x11_bytes_pixel );
  152.     if (x11_display_type & XA_X11_TRUE)
  153.     {
  154.       fprintf(stderr,"  X11 Color Masks =%lx %lx %lx\n",
  155.                   x11_red_mask,x11_green_mask ,x11_blue_mask);
  156.       fprintf(stderr,"  X11 Color Shifts=%ld %ld %ld\n",
  157.                   x11_red_shift, x11_green_shift, x11_blue_shift );
  158.       fprintf(stderr,"  X11 Color Sizes =%ld %ld %ld\n",
  159.                   x11_red_bits,x11_green_bits ,x11_blue_bits);
  160.     }
  161.     else if (x11_display_type == XA_MONOCHROME)
  162.     {
  163.       fprintf(stderr,"  Bit Order = %lx  bitmapunit = %lx\n",
  164.                 x11_bit_order,x11_bitmap_unit);
  165.     }
  166.     fprintf(stderr,"\n");
  167.   }
  168.  
  169.   /* kludges */
  170.   if (   (!(x11_display_type & XA_X11_TRUE))
  171.       && (x11_depth == 24) && (x11_cmap_size <= 256) ) x11_kludge_1 = TRUE;
  172. }
  173.